package cn.nebula.music.json;

import java.io.Serializable;

public class Result<T> implements Serializable{
	private Integer code;
	private String message;
	private boolean success = true;
	private T data;
	
	private Result() {
		
	}
	
	private Result(Integer code,String message) {
		this.code = code;
		this.message = message;
	}
	
	private Result(Integer code, T data, String message) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
	
	public static <T> Result<T> error() {
        return error(500, "未知异常，请联系管理员");
    }
 
    public static <T> Result<T> error(String message) {
        return error(500, message);
    }
 
    public static <T> Result<T> error(int code, String message) {
        Result result = new Result(code, message);
        result.setSuccess(false);
        return result;
    }
 
    public static <T> Result<T> error(int code, T data, String message) {
        Result result = new Result(code, data, message);
        result.setSuccess(false);
        return result;
    }
  
    public static <T> Result<T> success() {
        return success(null, "处理成功");
    }
 
    public static <T> Result<T> success(T data) {
        return success(data, "处理成功");
    }
 
    public static <T> Result<T> success(String message) {
        return success(null, message);
    }
 
    public static <T> Result<T> success(T data, String message) {
        return new Result(0, data, message);
    }
	
	public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	
	
}
